package com.cy.aircompressor.main.view.chart;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.cy.aircompressor.databinding.ItemLineNewDataBinding;
import com.cy.aircompressor.entity.linechart.LineNewData;

public class LatestDataView extends FrameLayout {
    private Context mContext;
    private ItemLineNewDataBinding mBinding;
    private LineNewData lineNewData;

    public LatestDataView(@NonNull Context context) {
        this(context, null);
    }

    public LatestDataView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LatestDataView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public LatestDataView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.mContext = context;
        initView();
    }

    private void initView() {
        mBinding = ItemLineNewDataBinding.inflate(LayoutInflater.from(getContext()));
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        addView(mBinding.getRoot(), layoutParams);
    }


    public void initLineNewData(LineNewData lineNewData) {
        this.lineNewData = lineNewData;
        mBinding.cylinderName.setText(lineNewData.getName());
        mBinding.cylinderUnit.setText(lineNewData.getUnit());
        mBinding.cylinderValue.setText("-");
    }

    public LineNewData getLineNewData() {
        return lineNewData;
    }

    public void setValue(String value) {
        mBinding.cylinderValue.setText(value);
    }

    public void setDefault() {
        mBinding.cylinderValue.setText("-");
    }

}
